Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.

DropkicK Json List matched to an empty C# List #27

Closed
wants to merge 3 commits into from

Conversation

plepropre
Copy link

Problem statement

While using DropkicK to manage the deployment of a C# project (.Net 4.5), we use Json files to describe deployment settings. Those are bound at run-time, by the Magnum library, against custom C# class files (extending dropkick.Configuration.Dsl.Deployment).

Unfortunately, JSON lists were bound to an empty List at runtime.

Magnum internal details

JsonValueProvider

Recursive calls in the JsonValueProvider, when reading the Json content, were wrongly linking each array item into a separate {key, value} pair within its internal dictionary.

ListBinder / EnumerableBinderBase

On the other end, the EnumerableBinderBase was binding an empty list to the custom c# deployment settings object, regardless of the context property value (that is, the list content).

Example

{
    BuildFolder: "..\\..\\build",
    ERPBinariesGroups: ["Binaries0","Binaries1","Binaries2","Binaries3"],
    IntegrationService: true,
    Debug: true
}
using dropkick.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Deployment
{
    public class MyDeploymentSettings: DropkickConfiguration
    {
        public string BuildFolder { get; set; }

        public List<string> ERPBinariesGroups { get; set; }

        public bool IntegrationService { get; set; }

        public bool Debug { get; set; }
    }
}

Considering the JSON sample, the internal dictionary of JsonValueProvider would have the following wrong content:

[
{ "BuildFolder",  "..\\..\\build" }, 
{ "ERPBinariesGroups[0]", "Binaries0" },
{ "ERPBinariesGroups[1]", "Binaries1" },
{ "ERPBinariesGroups[2]", "Binaries2" },
{ "ERPBinariesGroups[3]", "Binaries3" },
{ "IntegrationService", true },
{ "Debug", true }
]

The correct content should be:

[
{ "BuildFolder",  "..\\..\\build" }, 
{ "ERPBinariesGroups", ["Binaries0", "Binaries1", "Binaries2", "Binaries3"] },
{ "IntegrationService", true },
{ "Debug", true }
]

Therefore, at binding time (InstanceBinderContext), the binder would look to match the C# property ERPBinariesGroups to a context unable to match its request as it only knows the properties ERPBinariesGroups[i].

Few comments

Took me a while to figure the whole thing out. I don't recommend using my commits "as is" to fix the issue as I have disabled the rake tests task and hardcoded the string type for the List being recursively constructed in the JsonParser.
I looked at making the whole thing generic and a bit cleaner but that's the best I can do for the time being without breaking half of the API.

Hope this helps,

Pierre.

@plepropre plepropre changed the title Drop kick json list fix DropkicK Json List matched to an empty C# List Aug 26, 2015
@phatboyg phatboyg closed this Aug 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants